/*
============================================================================
 Name        : BitStream.h
 Author      : 
 Version     :
 Copyright   : Your copyright notice
 Description : CBitStream declaration
============================================================================
*/

#ifndef BITSTREAM_H
#define BITSTREAM_H

// INCLUDES
#include <e32std.h>
#include <e32base.h>
#include "XInt32.h"
#include "Goods.h"
// CLASS DECLARATION

class  TBitCode
{
public:
	TBitCode(TInt16 wCodeBits, TInt8 cCodeLen, TInt8 cDataType, TInt8 cDataLen, TInt dwDataBias);
public:
	TInt16	m_wCodeBits;
	TInt8	m_cCodeLen;
	TInt8	m_cDataType;	// 'C'-const, 'D'-DWORD, 'I'-INT32, 'X'-XInt32, 'H'-hundred DWORD, 'h'-hundred INT
	TInt8	m_cDataLen;
	TInt	m_dwDataBias;
#ifdef _DEBUG
	TInt16	m_dwCodeCount;
#endif
};


class CBitStreamConst : public CBase
{
public:
	CBitStreamConst();
	~CBitStreamConst();
	void ConstructL();
public:
	RPointerArray<TBitCode>  BC_DYNA_TIMEDIFF;
	RPointerArray<TBitCode>  BC_DYNA_PRICE_DIFF;
	RPointerArray<TBitCode>  BC_DYNA_PRICE_DIFFS;
	RPointerArray<TBitCode>  BC_DYNA_VOL;
	RPointerArray<TBitCode>  BC_DYNA_VOL_DIFF;
	RPointerArray<TBitCode>  BC_DYNA_VOL_DIFFS;
	RPointerArray<TBitCode>  BC_DYNA_AMNT;
	RPointerArray<TBitCode>  BC_DYNA_AMNT_DIFF;
	RPointerArray<TBitCode>  BC_DYNA_PRICE_INS;
	RPointerArray<TBitCode>  BC_DYNA_PRICE_MMP;
	RPointerArray<TBitCode>  BC_DYNA_PRICE_GAP;
	RPointerArray<TBitCode>  BC_DYNA_TRADENUM;
	RPointerArray<TBitCode>  BC_MIN_NUMBER;
	RPointerArray<TBitCode>  BC_MIN_TIME;
	RPointerArray<TBitCode>  BC_MINDAY_PRICE;
	RPointerArray<TBitCode>  BC_MINDAY_PRICE_DIFFS;
	RPointerArray<TBitCode>  BC_MINDAY_PRICE_DIFF;
	RPointerArray<TBitCode>  BC_MIN_VOL;
	RPointerArray<TBitCode>  BC_MINDAY_STRONG;
	RPointerArray<TBitCode>  BC_MINDAY_STRONG_DIFF;
	RPointerArray<TBitCode>  BC_DAY_NUMBER;
	RPointerArray<TBitCode>  BC_DAY_TIME;
	RPointerArray<TBitCode>  BC_DAY_TIME_MIND;
	RPointerArray<TBitCode>  BC_DAY_TIME_MINM;
	RPointerArray<TBitCode>  BC_DAY_VOL;
	RPointerArray<TBitCode>  BC_DAY_IND;
	RPointerArray<TBitCode>  BC_DAY_IND_DIFF;
	// MACD - DIF, DEA
	RPointerArray<TBitCode>  BC_EXP_MACD;
	// KDJ - K, D; RSI; WR
	RPointerArray<TBitCode>  BC_EXP_KDJ;
	RPointerArray<TBitCode>  BC_EXP_KDJ_DIFF;
	// VR
	RPointerArray<TBitCode>  BC_EXP_VR;
	RPointerArray<TBitCode>  BC_EXP_VR_DIFF;
	// \xC1\xBF\xB1\xC8
	RPointerArray<TBitCode>  BC_GRID_LB;
	// \xBB\xBB\xCA\xD6\xC2\xCA
	RPointerArray<TBitCode>  BC_GRID_HSL;
	// \xD5\xF0\xB7\xF9
	RPointerArray<TBitCode>  BC_GRID_ZF;
	RPointerArray<TBitCode>  BC_TRADE_NUMBER;
	RPointerArray<TBitCode>  BC_BARGAIN_TIMEDIFF;
	RPointerArray<TBitCode>  BC_TRADE_PRICE;
	RPointerArray<TBitCode>  BC_TRADE_PRICE_DIFFS;
	RPointerArray<TBitCode>  BC_BARGAIN_TRADENUM_DIFF;
	RPointerArray<TBitCode>  BC_BARGAIN_VOL;

	RPointerArray<TBitCode>  BC_DYNA_ZLZC;
	RPointerArray<TBitCode>  BC_AMT;
	RPointerArray<TBitCode>  BC_AMT_DIFF;
	RPointerArray<TBitCode>  BC_MINDAY_AMNT;
	RPointerArray<TBitCode>  BC_MINDAY_AMNT_DIFF;

	RPointerArray<TBitCode>  BC_BARGAIN_QH_VOL;
	RPointerArray<TBitCode>  BC_BARGAIN_QH_OI;
	RPointerArray<TBitCode>  BC_DYNA_QH_VOL_DIFF;
	RPointerArray<TBitCode>  BC_DYNA_QH_VOL_DIFFS;
};
/**
*  CBitStream
* 
*/
class TBitStream
{
public:
	~TBitStream();
	TBitStream(TPtrC8& pcBuf);

public:
	//void SetBuffer(TPtr8& pcBuf);
	//TInt ReallocBuf(const TUint& nBits);
	//TInt WriteDWORD(TInt dw, TInt nBits) ;
	TInt ReadDWORD(TInt nBits, TBool bMovePos);
	TBitCode*  MatchCodeEncode( TInt& dw,RPointerArray<TBitCode>& pBitCodes);
	//TInt EncodeData(TInt dwData,RPointerArray<TBitCode>& pBitCodes,
	//	TInt* pdwBase, TBool bReverse);
	//TInt EncodeXInt32(XInt32 xData, RPointerArray<TBitCode>& pBitCodes,
	//	XInt32* pxBase, TBool bReverse);
	TBitCode* MatchCodeDecode( TInt& dw,TUint8& cBytes,RPointerArray<TBitCode>& pBitCodes);
	TUint8 DecodeData(TInt& dwData, RPointerArray<TBitCode>& pBitCodes , TInt* pdwBase, TBool bReverse);
	TUint8 DecodeXInt32(XInt32& xData, RPointerArray<TBitCode>& pBitCodes ,XInt32* pxBase, TBool bReverse);
	TUint8 WriteBOOL(TBool bValue);
	void DecodeAllMMPPrice(TInt NUM_OF_MMP, TGoods& goods, TInt nIndex);
	void ExpandMMP(TGoods& goods, TUint8 bL2Encode);
	void ExpandMMP(TGoods& goods, TGoods& goodsOld, TUint8 bL2Encode);
	void ExpandVirtualMMP(TGoods& goods);
	void ExpandVirtualMMP(TGoods& goods, TGoods& goodsOld);
	
private:
	TPtrC8 m_pcBuf;
	TInt m_nBitLen;
	TInt m_nCurPos;

public:
	RPointerArray<TBitCode>&  BC_DYNA_TIMEDIFF;
	RPointerArray<TBitCode>&  BC_DYNA_PRICE_DIFF;
	RPointerArray<TBitCode>&  BC_DYNA_PRICE_DIFFS;
	RPointerArray<TBitCode>&  BC_DYNA_VOL;
	RPointerArray<TBitCode>&  BC_DYNA_VOL_DIFF;
	RPointerArray<TBitCode>&  BC_DYNA_VOL_DIFFS;
	RPointerArray<TBitCode>&  BC_DYNA_AMNT;
	RPointerArray<TBitCode>&  BC_DYNA_AMNT_DIFF;
	RPointerArray<TBitCode>&  BC_DYNA_PRICE_INS;
	RPointerArray<TBitCode>&  BC_DYNA_PRICE_MMP;
	RPointerArray<TBitCode>&  BC_DYNA_PRICE_GAP;
	RPointerArray<TBitCode>&  BC_DYNA_TRADENUM;
	RPointerArray<TBitCode>&  BC_MIN_NUMBER;
	RPointerArray<TBitCode>&  BC_MIN_TIME;
	RPointerArray<TBitCode>&  BC_MINDAY_PRICE;
	RPointerArray<TBitCode>&  BC_MINDAY_PRICE_DIFFS;
	RPointerArray<TBitCode>&  BC_MINDAY_PRICE_DIFF;
	RPointerArray<TBitCode>&  BC_MIN_VOL;
	RPointerArray<TBitCode>&  BC_MINDAY_STRONG;
	RPointerArray<TBitCode>&  BC_MINDAY_STRONG_DIFF;
	RPointerArray<TBitCode>&  BC_DAY_NUMBER;
	RPointerArray<TBitCode>&  BC_DAY_TIME;
	RPointerArray<TBitCode>&  BC_DAY_TIME_MIND;
	RPointerArray<TBitCode>&  BC_DAY_TIME_MINM;
	RPointerArray<TBitCode>&  BC_DAY_VOL;
	RPointerArray<TBitCode>&  BC_DAY_IND;
	RPointerArray<TBitCode>&  BC_DAY_IND_DIFF;
	// MACD - DIF, DEA
	RPointerArray<TBitCode>&  BC_EXP_MACD;
	// KDJ - K, D; RSI; WR
	RPointerArray<TBitCode>&  BC_EXP_KDJ;
	RPointerArray<TBitCode>&  BC_EXP_KDJ_DIFF;
	// VR
	RPointerArray<TBitCode>&  BC_EXP_VR;
	RPointerArray<TBitCode>&  BC_EXP_VR_DIFF;
	// \xC1\xBF\xB1\xC8
	RPointerArray<TBitCode>&  BC_GRID_LB;
	// \xBB\xBB\xCA\xD6\xC2\xCA
	RPointerArray<TBitCode>&  BC_GRID_HSL;
	// \xD5\xF0\xB7\xF9
	RPointerArray<TBitCode>&  BC_GRID_ZF;
	RPointerArray<TBitCode>&  BC_TRADE_NUMBER;
	RPointerArray<TBitCode>&  BC_BARGAIN_TIMEDIFF;
	RPointerArray<TBitCode>&  BC_TRADE_PRICE;
	RPointerArray<TBitCode>&  BC_TRADE_PRICE_DIFFS;
	RPointerArray<TBitCode>&  BC_BARGAIN_TRADENUM_DIFF;
	RPointerArray<TBitCode>&  BC_BARGAIN_VOL;

	RPointerArray<TBitCode>&  BC_DYNA_ZLZC;
	RPointerArray<TBitCode>&  BC_AMT;
	RPointerArray<TBitCode>&  BC_AMT_DIFF;
	RPointerArray<TBitCode>&  BC_MINDAY_AMNT;
	RPointerArray<TBitCode>&  BC_MINDAY_AMNT_DIFF;

	RPointerArray<TBitCode>&  BC_BARGAIN_QH_VOL;
	RPointerArray<TBitCode>&  BC_BARGAIN_QH_OI;
	RPointerArray<TBitCode>&  BC_DYNA_QH_VOL_DIFF;
	RPointerArray<TBitCode>&  BC_DYNA_QH_VOL_DIFFS;
};

#endif // BITSTREAM_H
